package demo.huodongbaoming.config;

import demo.huodongbaoming.entity.ActivityCategory;
import demo.huodongbaoming.repository.ActivityCategoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component
public class DataInitializer implements CommandLineRunner {

    @Autowired
    private ActivityCategoryRepository categoryRepository;

    @Override
    public void run(String... args) throws Exception {
        // 初始化活动类别
        if (categoryRepository.count() == 0) {
            List<String> categories = Arrays.asList(
                "学术讲座", "文体活动", "志愿服务", "社团活动", 
                "竞赛活动", "招聘宣讲", "实践活动", "其他"
            );
            
            for (String categoryName : categories) {
                ActivityCategory category = new ActivityCategory();
                category.setName(categoryName);
                category.setDescription(categoryName + "类活动");
                categoryRepository.save(category);
            }
            
            System.out.println("活动类别初始化完成");
        }
    }
} 